#include <stdio.h>
#include <pthread.h>

#define N   4

void *thread(void *arg)
{
    int myid = (int)arg;
    printf("hello from thread %d\n", myid);
    return NULL;
}

int main(int argc, char const* argv[])
{
    pthread_t tid[N];
    int i;

    for (i = 0; i < N; i++) {
        pthread_create(&tid[i], NULL, thread, (void *)i);
    }

    for (i = 0; i < N; i++) {
        pthread_join(tid[i], NULL);
    }

    return 0;
}
